﻿using System;

namespace DelegatesAndEventsTest
{
    class AnotherPerson : IPropertyChangeNotification
    {
        string firstName;
        string lastName;
        gender personGender;
        DateTime birthday; 
        private PropertyChangedEventHandler propertyChanged;

        public event PropertyChangedEventHandler PropertyChanged
        {
            add
            {
                propertyChanged += value;
                Console.WriteLine("Subscribed to {0} event.", value);
            }
            remove
            {
                propertyChanged -= value;
                Console.WriteLine("Unsubscribed to Button.Clicked event.");
            }
        }

        public string FirstName
        {
            get
            {
                return firstName;
            }
            set
            {
                string propertyName = "First Name";
                OnPropertyChanged(propertyName, this.firstName, value);
                firstName = value;
            }
        }

        public string LastName
        {
            get
            {
                return lastName;
            }
            set
            {
                string propertyName = "Last Name";
                OnPropertyChanged(propertyName, this.lastName, value);
                lastName = value;
            }
        }

        internal gender PersonGender
        {
            get
            {
                return personGender;
            }
            set
            {
                string propertyName = "Gender";
                OnPropertyChanged(propertyName, this.personGender, value);
                personGender = value;
            }
        }

        public DateTime Birthday
        {
            get
            {
                return birthday;
            }
            set
            {
                string propertyName = "Birth Date";
                OnPropertyChanged(propertyName, this.birthday, value);
                birthday = value;
            }
        }

        private void OnPropertyChanged(string propertyName, object oldValue, object newValue)
        {
            if (propertyChanged != null)
            {
                PropertyChangedEventArgs args = new PropertyChangedEventArgs(propertyName, oldValue, newValue);
                propertyChanged(this, args);
            }
        }
    }
}